package com.lyj.cloud.security;

import javax.annotation.Resource;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;

@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
	
	private static final String RESOURCE_ID = "service-rest-api";
	@Resource
	private RemoteTokenServices tokenService;
	
	@Override
	public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
		// TODO Auto-generated method stub
		resources.resourceId(RESOURCE_ID).tokenServices(tokenService).stateless(true);
	}
	
	@Override
	public void configure(HttpSecurity http) throws Exception {
		// TODO Auto-generated method stub
//		super.configure(http);
		http
		.authorizeRequests()
//			.antMatchers("/webjars*/**").permitAll()
//			.antMatchers("doc*/**","/swagger-ui.html").authenticated()
//		.and()
//			.httpBasic()
		.and()
			.authorizeRequests().anyRequest().authenticated();
	}
}
